{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "eAMjMVPbOL9H"
      },
      "outputs": [],
      "source": [
        "X = []\n",
        "y = []"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "import numpy as np\n",
        "\n",
        "df = pd.read_csv('/content/ppg.csv')\n",
        "\n",
        "selected_columns_index = [3, 6, 7, 2]\n",
        "selected_data = df.iloc[:, selected_columns_index]\n",
        "\n",
        "selected_data.iloc[:, -1] = selected_data.iloc[:, -1].apply(lambda x: 1 if x == 'Female' else 0)\n",
        "\n",
        "data_array = selected_data.to_numpy()\n",
        "data_array[0] = data_array[10]  # Just an example modification\n",
        "\n",
        "# Convert the data array to integers\n",
        "data_array = data_array.astype(int)\n",
        "\n",
        "\n"
      ],
      "metadata": {
        "id": "uGsR9XOiPtdJ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "# Read the CSV file into a DataFrame\n",
        "df = pd.read_csv('/content/dsp_data.csv')\n",
        "\n",
        "# Define the values for the new column\n",
        "new_column_values = y  # Example values for the new column\n",
        "\n",
        "# Add the new column to the DataFrame\n",
        "df['Activity'] = new_column_values\n",
        "\n",
        "# Define the filename\n",
        "filename = \"dsp_data.csv\"\n",
        "\n",
        "# Write the DataFrame to a CSV file\n",
        "df.to_csv(filename, index=False)\n"
      ],
      "metadata": {
        "id": "vW-Hq450q0B2"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "import pandas as pd\n",
        "\n",
        "# Read the CSV file into a DataFrame\n",
        "df = pd.read_csv('/content/dsp_data.csv')\n",
        "\n",
        "# Select the first four columns as features (X) and the fifth column as target (y)\n",
        "X = df.iloc[:, :4].values\n",
        "y = df.iloc[:, 4].values\n",
        "\n",
        "# Optionally, if you want to convert y to integers, you can do so like this:\n",
        "# y = y.astype(int)\n",
        "\n",
        "# Print the first few rows of X and y to verify\n",
        "print(\"X (features):\")\n",
        "print(X[:5])  # Printing first 5 rows for demonstration\n",
        "print(\"\\ny (target):\")\n",
        "print(y[:5])  # Printing first 5 rows for demonstration\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "xxT2v286sVky",
        "outputId": "922885ca-a5ae-49eb-c9f3-3e4930f3339f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "X (features):\n",
            "[[ 47  98  56   1]\n",
            " [ 45 161  89   1]\n",
            " [ 50 160  93   1]\n",
            " [ 47 101  71   1]\n",
            " [ 45 136  93   0]]\n",
            "\n",
            "y (target):\n",
            "[1 2 1 1 2]\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import numpy as np\n",
        "import os\n",
        "from sklearn.utils import shuffle\n",
        "\n",
        "import librosa\n",
        "from sklearn.model_selection import train_test_split\n",
        "from sklearn.ensemble import RandomForestClassifier\n",
        "from sklearn.metrics import accuracy_score\n",
        "X, y = shuffle(X, y, random_state=75)\n",
        "\n",
        "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=75)\n",
        "\n",
        "clf = RandomForestClassifier(n_estimators=70, random_state=75)\n",
        "clf.fit(X_train, y_train)\n",
        "\n",
        "y_pred = clf.predict(X_test)\n",
        "\n",
        "accuracy = accuracy_score(y_test, y_pred)\n",
        "print(\"Accuracy:\", accuracy)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "-_kaxqy7pus_",
        "outputId": "985f22a7-b56f-4c77-8d3b-6a0bbdf1de35"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Accuracy: 0.9318181818181818\n"
          ]
        }
      ]
    }
  ]
}